<script>
import { getMenuItems } from './menus.js';
import TabSwitching from '@/components/TabSwitching/TabSwitching.vue';
export default {
    // eslint-disable-next-line vue/multi-word-component-names
    name: 'Accordion',
    components: { TabSwitching },
    data() {
        return {
            menuItems: getMenuItems(),
            dataList: [
                {
                    title: '标题1',
                    content: '不要等待机会，而要创造机会。',
                    icon: require('@/assets/images/accordion/1.png'),
                    bgImg: 'https://img1.baidu.com/it/u=1097951435,212878480&fm=253&fmt=auto&app=138&f=JPEG?w=800&h=1428',
                    active: 'active'
                },
                {
                    title: '标题2',
                    content: '路漫漫其修远兮，吾将上下而求索。',
                    icon: require('@/assets/images/accordion/2.png'),
                    bgImg: 'https://img0.baidu.com/it/u=2002946541,3743076397&fm=253&fmt=auto&app=138&f=JPEG?w=800&h=1066',
                    active: ''
                },
                {
                    title: '标题3',
                    content: '世界会向那些有目标和远见的人让路。',
                    icon: require('@/assets/images/accordion/3.png'),
                    bgImg: 'https://img1.baidu.com/it/u=1361177696,203903602&fm=253&fmt=auto&app=138&f=JPEG?w=800&h=1455',
                    active: ''
                },
                {
                    title: '标题4',
                    content: '我达到目标的惟一的力量就是我的坚持精神。',
                    icon: require('@/assets/images/accordion/4.png'),
                    bgImg: 'https://img0.baidu.com/it/u=3841374795,2794980821&fm=253&fmt=auto&app=138&f=JPEG?w=800&h=1200',
                    active: ''
                },
                {
                    title: '标题5',
                    content: '人类因梦想而伟大，人生因拼搏而精彩。',
                    icon: require('@/assets/images/accordion/5.png'),
                    bgImg: 'https://img0.baidu.com/it/u=3578545025,1094908763&fm=253&fmt=auto&app=138&f=JPEG?w=800&h=1522',
                    active: ''
                }
            ]
        };
    },
    methods: {
        handlehover(index) {
            this.dataList.forEach((item, i) => {
                if (i === index) {
                    item.active = 'active';
                } else {
                    item.active = '';
                }
            });
        }
    }
};
</script>

<template>
    <div>
        <!--切换组件-->
        <tab-switching :account="0" :data="menuItems" />
        <!--特效内容-->
        <div class="accordion-box">
            <div v-for="(item, index) in dataList" :key="index" :class="item.active" class="accordion-item" @mouseup="handlehover(index)">
                <div class="accordion-bg" :style="{ backgroundImage: `url(${item.bgImg})` }"></div>
                <div class="accordion-content">
                    <div class="accordion-header">
                        <div class="accordion-icon">
                            <img :alt="item.title" :src="item.icon" />
                        </div>
                        <div class="accordion-title">
                            <span>{{ item.title }}</span>
                        </div>
                    </div>
                    <div class="accordion-text">
                        <span>{{ item.content }}</span>
                    </div>
                </div>
            </div>
        </div>
    </div>
</template>

<style lang="scss" scoped>
.accordion-box {
    display: flex;
    flex-wrap: nowrap;
    justify-content: space-between;
    align-items: center;
    margin: 0 auto;
    width: 530px;
    padding: 20px;
    box-sizing: border-box;
    .accordion-item {
        position: relative;
        width: 60px;
        height: 300px;
        margin-bottom: 20px;
        border-radius: 10px;
        padding: 3px;
        border: 2px solid #ffffff;
        overflow: hidden;
        cursor: pointer;
        transition: width 0.5s ease-in-out;
        .accordion-bg {
            width: 100%;
            height: 100%;
            padding: 10px;
            box-sizing: border-box;
            background-size: auto;
            background-repeat: no-repeat;
            background-position: center;
            border-radius: 10px;
        }
        .accordion-content {
            position: absolute;
            top: 0;
            left: 0;
            z-index: 1;
            width: 100%;
            height: 100%;
            padding: 10px;
            box-sizing: border-box;
            border-radius: 10px;
            .accordion-header {
                display: flex;
                flex-wrap: nowrap;
                justify-content: flex-start;
                color: #fff;
                gap: 20px;
                .accordion-icon {
                    width: 40px;
                    height: 40px;
                    flex-shrink: 0;
                    background-color: rgba(204, 204, 204, 0.5);
                    border-radius: 50%;
                    overflow: hidden;
                    img {
                        width: 80%;
                        padding: 10%;
                    }
                }
                .accordion-title {
                    opacity: 0;
                    line-height: 40px;
                    width: 100%;
                    flex-shrink: 0;
                    font-size: 20px;
                }
            }
            .accordion-text {
                padding: 0 10px;
                opacity: 0;
                transform: translateY(40px);
            }
        }
        &.active {
            border: 2px solid #669295;
            width: 200px;
            .accordion-bg {
                filter: brightness(50%);
            }
            .accordion-content {
                .accordion-header {
                    .accordion-title {
                        opacity: 1;
                        color: #ffffff;
                        filter: brightness(100%);
                    }
                }
                .accordion-text {
                    opacity: 1;
                    color: #ffffff;
                    transform: translateY(20px);
                    // 延迟一秒执行
                    transition: opacity 0.2s ease-in 0.5s, transform 0.5s ease-in 0.7s;
                }
            }
        }
    }
}
</style>
